<form method="post" enctype="multipart/form-data" target="_blank" id="form-order">
  <div class="table-responsive">
    <table class="table table-bordered table-hover">

      <thead>
      <tr>
        <td class="text-center" ><input type="checkbox" id="checkAll"></td>
        <td class="text-center" width="65px;">序号</td>
        <td class="text-center">卡号</td>
        <td class="text-center">卡密</td>
        <td class="text-center">用户电话</td>
        <td class="text-center">面额</td>
        <td class="text-center">状态</td>
        <td class="text-center">创建时间</td>
        <td class="text-center">使用时间</td>
        <td class="text-center">激活状态</td>
        <td class="text-center">操作</td>
      </tr>
      </thead>

      <tbody>
      <volist name="list" id="list">
        <tr id="list">
          <td class="text-center"><input type="checkbox" class="check" value="{$list.id}"></td>
          <td class="text-center">{$list.id}</td>
          <td class="text-center">{$list.card_number}</td>
          <if condition="$viewType == 1 ">
            <td class="text-center">{$list.card_password}</td>
            <else />
            <td class="text-center">********</td>
          </if>
          <td class="text-center">{$list.userMobile}</td>
          <td class="text-center">{$list.denomination}</td>
          <td class="text-center">{$list.states}</td>
          <td class="text-center">{$list.createtime}</td>
          <td class="text-center">{$list.usagetime}</td>
          <td class="text-center">
            <if condition="$list.activation_type == '1'">
              <span style="color: red">未激活</span>
              <else />
              <span style="color: green">已激活</span>
            </if>
          </td>
          <td class="text-center">
            <if condition="$list.activation_type == '1'">
              <a href="javascript:;" onclick="activation(this)" data-url="{:url('rechargeable/activation')}" data-id="{$list.id}"  class="btn btn-primary" title="激活">激活</a>
            </if>
            <a href="javascript:;" onclick="delfunc(this)" data-url="{:url('rechargeable/del')}" data-id="{$list.id}"  class="btn btn-danger" title="删除"><i class="fa fa-trash-o"></i></a>
          </td>
        </tr>
      </volist>

      </tbody>
    </table>
  </div>
</form>
<div class="row">
  <div class="col-sm-3 text-left"></div>
  <div class="col-sm-9 text-right">{$page}</div>
</div>
<script>
  // 点击分页触发的事件
  $(".pagination  a").click(function(){
    cur_page = $(this).data('p');
    console.log(cur_page);
    ajax_get_tables('search-form', cur_page);
  });

  $(document).ready(function() {
    // 全选复选框被选中时，所有其他复选框也被选中
    $('#checkAll').change(function() {
      $('.check').prop('checked', $(this).prop('checked'));
    });

    // 检测其他复选框的选中状态，如果所有复选框都被选中，就选中全选复选框
    $('.check').change(function() {
      if($('.check:checked').length == $('.check').length) {
        $('#checkAll').prop('checked', true);
      } else {

        $('#checkAll').prop('checked', false);
      }
    });
  });

  //导出-获取所有选中的值
  $("#getValue").click(function(){
    var arr = [];
    $(".check:checked").each(function(i){
      arr[i] = $(this).val();
    })
    console.log(arr);
    location.href = '/mingteng/rechargeable/export?ids='+arr;
  })

  //批量激活-获取所有选中的值
  $("#activationAll").click(function(){
    var arr = [];
    $(".check:checked").each(function(i){
      arr[i] = $(this).val();
    })
    layer.confirm('确认激活？', function(){
              $.ajax({
                type : 'post',
                url : "{:url('rechargeable/activationAll')}",
                data : {
                  ids:arr,
                },
                dataType : 'json',
                success : function(data){
                  if(data.code == 200){
                    layer.msg('操作成功', {icon: 1, time: 1000}, function (){
                      window.location.reload();
                    });
                  }else{
                    layer.alert(data.msg, {icon: 2,time: 2000});
                  }
                }
              })
            }
    );
  })

  function activation(obj){
    layer.confirm('确认激活？', function(){
              $.ajax({
                type : 'post',
                url : $(obj).attr('data-url'),
                data : {id:$(obj).attr('data-id')},
                dataType : 'json',
                success : function(data){
                  if(data.code == 200){
                    layer.msg('操作成功', {icon: 1, time: 1000}, function (){
                      window.location.reload();
                    });
                  }else{
                    layer.alert(data.msg, {icon: 2,time: 2000});
                  }
                }
              })
            }
    );
  }
</script>